﻿using System.Reflection;
using System;

namespace Inovout.Descriptors
{
    public class PropertyDescriptor : MemberDescriptor, IValueGetter
    {
        private PropertyInfo propertyInfo;
        public PropertyDescriptor(PropertyInfo propertyInfo)
            :base(propertyInfo)
        {
            this.propertyInfo = propertyInfo;
        }
        public bool IsReadOnly
        {
            get { return !propertyInfo.CanWrite; }
        }
        public Type PropertyType
        {
            get { return propertyInfo.PropertyType; }
        }

        public object GetValue(object instance)
        {
            return propertyInfo.GetValue(instance,null);
        }

        public void SetValue(object instance, object value)
        {
           // if (propertyInfo.CanWrite)
          //  {
                propertyInfo.SetValue(instance, value,null);
         //   }
        }
    }
}
